﻿using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using Usas.Model.Cms;
namespace Usas.BLL.Cms
{
    /// <summary>
    /// 业务逻辑类cmsReview 的摘要说明。
    /// </summary>
    public class cmsReview
    {
        private readonly Usas.DAL.Cms.cmsReview dal = new Usas.DAL.Cms.cmsReview();
        public cmsReview()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long ReviewId)
        {
            return dal.Exists(ReviewId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Usas.Model.Cms.cmsReview model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Usas.Model.Cms.cmsReview model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(long ReviewId)
        {

            dal.Delete(ReviewId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Usas.Model.Cms.cmsReview GetModel(long ReviewId)
        {

            return dal.GetModel(ReviewId);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public Usas.Model.Cms.cmsReview GetModelByCache(long ReviewId)
        {

            string CacheKey = "cmsReviewModel-" + ReviewId;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ReviewId);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Usas.Model.Cms.cmsReview)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Usas.Model.Cms.cmsReview> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Usas.Model.Cms.cmsReview> DataTableToList(DataTable dt)
        {
            List<Usas.Model.Cms.cmsReview> modelList = new List<Usas.Model.Cms.cmsReview>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Usas.Model.Cms.cmsReview model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Usas.Model.Cms.cmsReview();
                    //model.ReviewId=dt.Rows[n]["ReviewId"].ToString();
                    //model.ArtId=dt.Rows[n]["ArtId"].ToString();
                    model.Reviewer = dt.Rows[n]["Reviewer"].ToString();
                    model.Content = dt.Rows[n]["Content"].ToString();
                    if (dt.Rows[n]["EditTime"].ToString() != "")
                    {
                        model.EditTime = DateTime.Parse(dt.Rows[n]["EditTime"].ToString());
                    }
                    if (dt.Rows[n]["IsCheck"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsCheck"].ToString() == "1") || (dt.Rows[n]["IsCheck"].ToString().ToLower() == "true"))
                        {
                            model.IsCheck = true;
                        }
                        else
                        {
                            model.IsCheck = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

